<template>
	<view>
		<input v-model="text"/><button @click="send">fs</button>
		<text v-for="i in sMsg">{{i.data}}</text>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				text:'',
				sMsg:{}
			}
		},
		 computed: {
		    //监听接收到的消息
			socketMsgs() {
				return this.$websocket.getters.socketMsgs
		    }
		},
		watch: {
			'socketMsgs': {
		        //处理接收到的消息
				handler: function() {
				    let that = this
					console.log("接收到msg")
					this.sMsg = that.socketMsgs
					console.log(this.sMsg)
		          }
			}
		}, 

		created() {

		},
		
		methods: {
			socketMsgs() {
					return this.$websocket.getters.socketMsgs
			    },
			send() {
				let message = new Object();
				message.fromUid = 2 + '';
				message.toUid = 14 + '';
				message.content = this.text;
				
				var ta = JSON.stringify(message);
				this.$websocket.commit('webSocketSend', ta)
			
				this.$websocket.state
				}
		}
	}
</script>

<style>

</style>
